package com.opencvjava.support.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;
import java.util.concurrent.TimeUnit;

public class CommonUtils {

    private static final Logger LOG = LoggerFactory.getLogger(CommonUtils.class);

    public static void cost(String info, long start) {
        LOG.error(info + " cost:{}ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
    }

    public static void cost(long start, Object obj) {
        LOG.error(obj.getClass().getSimpleName() + " cost:{}ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
    }

    public static String classPath(String fileName) {
        try {
            return ResourceUtils.getURL("classpath:images/" + fileName).getPath().substring(1);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
